$(document).ready(function(){
		
		$(".ajaxdel").each(function(){
			$(this).bind("click",function(){del(this);});
		});
		
		$(".sayhello").click(function(){
			var url = $(this).attr("href");
			$.get(url,{ajax:1},function(data){
				if("success" == data){
					msg($(".sayhello"),"打招呼成功");
				}else if("error"==data){
					msg($(".sayhello"),"操作失败，你可以重试");
				}else{
					msg($(".sayhello"),"已经打过招呼");
				}
			});
			return false;
		});
		$(".friendaction").click(function(){
			var url = $(this).attr("href");
			$.get(url,{ajax:1},function(data){
				var href = $(".friendaction").attr("href");
				if("requestsuccess" == data){//好友申请
					$(".friendaction").attr("href",url.replace("sendrequest","remove"));
					$(".friendaction").text("已经发送申请,撤消?");
				}else if("removerequestsuccess" == data){ //撤消好友申请
					$$(".friendaction").attr("href",url.replace("remove","sendrequest"));
					$(".friendaction").text("加为好友");
				}else{
					msg($(".friendaction"),"操作失败，你可以重试");
				}
			});
			return false;
		});
		$(".delfriend").click(function(){
			alertMessage(this,"确定删除这个好友?");
			$(".msgOk").bind("click",function(){
				location.href = $(this).attr(href);
			});
			return false;
		});

		$("#guestform").submit( 
			function() { 
				if($.trim($("#guestcontent", this).val()).length < 2){
					$("#guestcontent").addClass("error");
					$("#guestcontent").focus();
					return false;
				}else{
					$.post($(this).attr("action"),{ajax:1,userid:$("#userid").val(),content:$("#guestcontent").val()},function(data){
						if("error" == data){
							msg($("#guestcontent"),"操作失败，你可以重试");
						}else{
							var arr = data.split(","); //用josn数据更好,eval下就成。
							var html= '<li class="guest">';
							html += '<div><div class="guestface">';
							html += '<a href="'+APP+'/user/index/u/'+arr[0];
							html += '"><img src="/Public/Uploads/'+arr[0]+'/face/small_face.jpg"/></a>';
							html += '</div><div class="guestcontent">';
							html += '<div class="app_title3"><a href="'+APP+'/user/index/u/'+arr[0]+'">'+arr[1]+'</a> <span class="li_time">'+arr[2]+'</span></div>';
							html += '<div class="content">'+$("#guestcontent").val()+'</div>';
							html += '</div></div></li>';
							$("#guestlist").prepend(html);
							$("#guestcontent").removeClass("error");
							$("#guestcontent").val("");
						}
					});
					return false
				}
			} 
		);
});

